package com.bountytask.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.bountytask.dao.CollectDao;
import com.bountytask.entity.Collect;
import com.bountytask.service.CollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;;
import java.util.List;

@Service
public class CollectServiceImpl implements CollectService {
    @Autowired
    private CollectDao collectDao;

    /**
     * 删除收藏任务
     * @param userid
     * @param taskid
     * @return
     */
    public int deleteTask(long userid,long taskid){
        return collectDao.deleteTask(userid,taskid);
    }
    /**
     * 添加收藏任务
     */
    public JSONObject addTask(long userid, long taskid){
        Collect collect = new Collect();
        collect.setTaskId(taskid);
        collect.setUserId(userid);
        int flag = collectDao.addTask(collect);
        JSONObject data = new JSONObject(true);
        JSONObject resultJson = new JSONObject(true);
        data.put("id",collect.getId());
        if (flag!=0){
            resultJson.put("code",200);
            resultJson.put("message","成功");
            resultJson.put("data",data);
            return resultJson;
        }
        resultJson.put("code",400);
        resultJson.put("message","失败");
        return  resultJson;
    }
    /**
     * 查询收藏任务
     */
    public List<Collect> getCollectAll(long userid){
        return collectDao.getCollectAll(userid);
    }
}
